<?php
namespace Admin\Controller;

class ProjectMonthController extends AbstractController  {
	
	protected $Form;

	public function _initialize(){
		$this->Form = D('Monthreport');
    }
    
    public function index(){
    	$id = (int)I('id');
    	$this->assign("projectID",$id);
    	$res = $this->Form->MyshowList();
		$this->assign("list",$res['list']);
    	$this->assign("page",$res['page']);
    	$this->display("Project/ProjectMonth/index");
    }
	
	public function save($type = false, $id = 0){
		if($type != false){
			if($type == "add"){
				$result = $this->Form->Myupadd();
			}else if($type == "edit"){
				if(I('id')){
					$res = $this->Form->Myshow(array("ID" => (int)I('id')));
					$this->assign("editdata",$res);
					$this->assign("data",$this->Form->getProjectList());
					$this->assign("tatusList",$this->Form->getStatusList());
				}
				$this->display("Project/ProjectMonth/save");
			}else if($type == "update"){
				$result = $this->Form->Myupdata();
			}else if($type == "table"){
				$res = $this->Form->getTableData();
				$this->ajaxReturn($res);
			}
			if($result['state'] == 1 && !empty($result)){
				$this->success($result['msg']);
			}else if($result['state'] == 0 && !empty($result)){
				$this->error($result['msg']);
			}
		}else{
			$res = $this->Form->getStatusList();
			$this->assign("tatusList",$res);
			$res = $this->Form->getProjectList();
			$this->assign("data",$res);
			$this->display("Project/ProjectMonth/save");
		}
	}
	
	public function table(){
		$id = (int)I('id');
		if(!empty($id)){
			$this->assign("id",$id);
		}
		$res = M("datadict as a")->field("b.ID")->join(" LEFT JOIN datadict AS b ON a.ID = b.ParentID ")->where(array("a.Name"=>"项目进行状态"))->select();
		$join2 =  " LEFT JOIN user AS b ON a.ChargeUserID = b.ID";
		$res2 = M("project")->alias('a')->field("a.Name,a.ImportantPoint,a.StartDate,a.EndDate,b.UserName")->join($join2)->where(array("a.ID"=>$_GET['id']))->find();
		$res3 = M("project_user_rel as a")->field("b.UserName")->join("LEFT JOIN user AS b ON a.UserID = b.ID")->where(array("a.ProjectID"=>$_GET['id']))->select();
		if(!empty($res3)){
			foreach($res3 AS $k => $v){
				$member .= $v['UserName'].',';
			}
		}
		$this->assign("projectName",$res2['Name']);
		$this->assign("ChargeUserName",$res2['UserName']);
		$this->assign("projectMember",substr($member,0,-1));
		$this->assign("dict",$res);
		$this->display("Project/ProjectMonth/table");
	}
	
	
	

}